package mvcdemo.controller;

import com.nf.mvc.HandlerContext;
import com.nf.mvc.argument.RequestBody;
import com.nf.mvc.argument.RequestParam;
import com.nf.mvc.mapping.RequestMapping;
import com.nf.mvc.view.JsonViewResult;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

@RequestMapping("/product")
public class ProductController {
    @RequestMapping("/list")
    public void m1(HttpServletRequest request){
        System.out.println("request.hashCode() = " + request.hashCode());
        System.out.println("HandlerContext.getContext().getRequest().hashCode() = " + HandlerContext.getContext().getRequest().hashCode());
        System.out.println("request.getMethod() = " + request.getMethod());
        System.out.println("m1 1---------------");
    }

    @RequestMapping("/list2")
    public void m2(){
        String method = HandlerContext.getContext().getRequest().getMethod();
        System.out.println("method = " + method);

        System.out.println("m1 2---------------");
    }

    @RequestMapping("/insert")
    public JsonViewResult insert(int id,String name){
        System.out.println("========insert=======");
        System.out.println("id="+id);
        System.out.println("name="+name);
        return new JsonViewResult(new ResponseVo(200,"ok",true));
    }

    @RequestMapping("/delete")
    public JsonViewResult delete(Integer[] ids, List<Integer> id2s,Emp emp){
        System.out.println("------delete-----------");
        System.out.println("ids.length = " + ids.length);
        System.out.println("ids="+ Arrays.toString(ids));
        System.out.println("id2s.size() = " + id2s.size());
        System.out.println("emp = " + emp);
        id2s.forEach(System.out::println);
        return new JsonViewResult(new ResponseVo(200,"ok",true));
    }

    @RequestMapping("/page")
    public JsonViewResult page(@RequestParam("no")int pageNo,
                               @RequestParam(defaultValue = "5")String pageSize){
        System.out.println("pageNo = " + pageNo);
        System.out.println("pageSize = " + pageSize);
        return new JsonViewResult(new ResponseVo(200,"ok",true));
    }

    @RequestMapping("/json")
    public JsonViewResult json(@RequestBody Emp emp){
        System.out.println("emp = " + emp);
        return new JsonViewResult(new ResponseVo(200,"ok",true));
    }
}
